package com.ruoyi.selectionRecords.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.selectionRecords.domain.UoocCourseSelection;
import com.ruoyi.selectionRecords.service.IUoocCourseSelectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 选课记录Controller
 * 
 * @author LGJ
 * @date 2025-07-08
 */
@RestController
@RequestMapping("/course/selection")
public class UoocCourseSelectionController extends BaseController
{
    @Autowired
    private IUoocCourseSelectionService uoocCourseSelectionService;

    /**
     * 查询选课记录列表
     */
    @PreAuthorize("@ss.hasPermi('course:selection:list')")
    @GetMapping("/list")
    public TableDataInfo list(UoocCourseSelection uoocCourseSelection)
    {
        startPage();
        List<UoocCourseSelection> list = uoocCourseSelectionService.selectUoocCourseSelectionList(uoocCourseSelection);
        return getDataTable(list);
    }
    /**
     * 根据学生ID查询选课记录
     */
    @PreAuthorize("@ss.hasPermi('course:selection:query')")
    @GetMapping("/student/{studentId}")
    public AjaxResult getByStudentId(@PathVariable("studentId") Long studentId) {
        UoocCourseSelection query = new UoocCourseSelection();
        query.setStudentId(studentId);
        List<UoocCourseSelection> list = uoocCourseSelectionService.selectUoocCourseSelectionList(query);
        return success(list);
    }
    /**
     * 根据课程ID查询选课记录
     */
    @PreAuthorize("@ss.hasPermi('course:selection:query')")
    @GetMapping("/course/{courseId}")
    public AjaxResult getByCourseId(@PathVariable("courseId") Long courseId) {
        UoocCourseSelection query = new UoocCourseSelection();
        query.setCourseId(courseId);
        List<UoocCourseSelection> list = uoocCourseSelectionService.selectUoocCourseSelectionList(query);
        return success(list);
    }

    /**
     * 导出选课记录列表
     */
    @PreAuthorize("@ss.hasPermi('course:selection:export')")
    @Log(title = "选课记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UoocCourseSelection uoocCourseSelection)
    {
        List<UoocCourseSelection> list = uoocCourseSelectionService.selectUoocCourseSelectionList(uoocCourseSelection);
        ExcelUtil<UoocCourseSelection> util = new ExcelUtil<UoocCourseSelection>(UoocCourseSelection.class);
        util.exportExcel(response, list, "选课记录数据");
    }

    /**
     * 获取选课记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:selection:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(uoocCourseSelectionService.selectUoocCourseSelectionByRecordId(recordId));
    }

    /**
     * 新增选课记录
     */
    @PreAuthorize("@ss.hasPermi('course:selection:add')")
    @Log(title = "选课记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UoocCourseSelection uoocCourseSelection)
    {
        return toAjax(uoocCourseSelectionService.insertUoocCourseSelection(uoocCourseSelection));
    }

    /**
     * 修改选课记录
     */
    @PreAuthorize("@ss.hasPermi('course:selection:edit')")
    @Log(title = "选课记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UoocCourseSelection uoocCourseSelection)
    {
        return toAjax(uoocCourseSelectionService.updateUoocCourseSelection(uoocCourseSelection));
    }

    /**
     * 删除选课记录
     */
    @PreAuthorize("@ss.hasPermi('course:selection:remove')")
    @Log(title = "选课记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(uoocCourseSelectionService.deleteUoocCourseSelectionByRecordIds(recordIds));
    }
}
